#include<stdio.h>
#include<stdlib.h>
#include <string.h>
//#include<conio.h>
//构造体
struct student{    	  	  	 	 
    int id;          //学生学号
    int score;          //考试成绩
    struct student *next;
}    	  	  	 	 *head; //1
  
//函数声明
void creat();
void output();
void delet(int id);
void Pfree(struct student *head);
  
int main()              
{   int id ;  //1
    creat();                        //1
    printf("学生的成绩信息为：\n");
    printf("id score\n");
    output();              //1
    printf("请输入需要删除成绩信息的学号：\n"); 
    scanf("%d",&id); //1
    delet(id);              //2
    Pfree(head);      //1
}    	  	  	 	 
//创建单链表保存学生信息，并输出学生信息
void  creat()   //2
{                         
    int number,i;
    struct student *q ,*tail;     //1
     struct student *out;
    head =(struct student*)malloc(sizeof(struct student));        //1
    head->next = NULL;
      
    tail = head;                     //1
    printf("请输入班级人数：\n");
    scanf("%d",&number);
    printf("请依次输入每个学生的学号 成绩\n");
    for( i = 0;i<number;i++)       //1
    {                        
        printf("请输入第%d个学生的成绩信息：\n",i+1);
        q =(struct student*)malloc(sizeof(struct student));       //1
        q->next = NULL;                          //1
        scanf("%d %d",&q->id,&q->score);   //1
        tail->next = q;                        //1
        tail = q;
}    	  	  	 	 
    
     
}    	  	  	 	 
  
void output()   //2
{               
 struct student *out;   //1
  out = head->next;                 
    while(out)  //1
    {    	  	  	 	 
        printf("%d %d\n",out->id,out->score);   //1   
        out = out->next;                 //1
    }
}    	  	  	 	 
void delet(int id) //2
{    	  	  	 	 
   struct student *p, *q = NULL; //1
  //  int j;
    q=head;
    p=head->next;
    for ( ;p->id !=id; )//2
    {    	  	  	 	 
        q=p;                 
        p = p->next;                 //1
        if (p == NULL)                 //1
        {printf("不存在！");
        return;}
    }
    q->next=p->next;                //1
    printf("删除成功！\n");
    output();                           //1
    free(p);                   //1
}    	  	  	 	 
  
void Pfree(struct student *head)//2
{    	  	  	 	 
   struct student *p, *q; //1
    p = head;
    while (p->next != NULL) //1
    {    	  	  	 	 
        q = p->next;
        p->next = q->next;//1
        free(q);//1
    }
    free(p);
}    	  	  